﻿namespace Pibby.Core.IO
{
	using System.IO;

	/// <summary>
	/// Creates IFile objects from files passed to it by the DirectoryProcessor
	/// </summary>
	public class FileListVisitor : IFileVisitor
	{
		#region Constructors

		public FileListVisitor()
		{
			this.Items = new IFileCollection();
		}

		#endregion

		public IFileCollection Items
		{
			get;
			private set;
		}

		#region IFileVisitor

		public bool Visit(IFile file)
		{
			this.Items.Add(file);

			return true;
		}

		public void Entering(IFolder folder)
		{
		}

		public void Leaving(IFolder folder)
		{
		}

		#endregion IFileVisitor

		public void ListContentsOf(IFolder startingPoint)
		{
			this.ListContentsOf(startingPoint, SearchOption.AllDirectories);
		}

		public void ListContentsOf(IFolder startingPoint, SearchOption option)
		{
			this.ListContentsOf(startingPoint, option, FileFilterConstants.AllFiles);
		}

		public void ListContentsOf(IFolder startingPoint, SearchOption option, string searchMask)
		{
			FileDiscoverer discoverer = new FileDiscoverer(this, option, searchMask);

			discoverer.Process(startingPoint);
		}
	}
}
